#include <iostream>
/*
	Modify C14:Combined.cpp so that f( ) is virtual in the base class. 
	Change main( ) to perform an upcast and a virtual call.
*/

using namespace std;

class A {
	int i;
public:
	A(int ii) : i(ii) {}
	~A() {}
	void f() const {
		cout << "the f() of A is called." << endl;
	}
};

class B {
	int i;
public:
	B(int ii) : i(ii) {}
	~B() {}
	virtual void f() const {
		cout << "the f() of B is called." << endl;
	}
};

class C : public B {
	A a;
public:
	C(int ii) : B(ii), a(ii) {}
	~C() {} // Calls ~A() and ~B()
	void f() const {  // Redefinition
		a.f();
		B::f();
		cout << "the f() of C is called." << endl;
	}
};

int main() {
	B* b = new C(5);
	b->f();
} 